<template>
    <span>{{ buildSerialNumber }}</span>
<!--  <span>{{ snPreviewModel }}</span>-->
</template>

<script setup lang="ts">
import { FormDataApi } from '@/api/res/FormData'
import { useApprovalDesignerStore } from '@/store/modules/dsgn/ApprovalDesigner'
import { SnWidgetItemType } from '@/components/FormCreate/src/config/SerialNumber/UseSerialNumberRule'
import { computed } from 'vue'

defineOptions({
  name: 'SerialNumber'
})

const designer = inject('designer')

// 接受父组件参数
interface Props {
  snKey: string
  snEditor: SnWidgetItemType[]
  modelValue: SnWidgetItemType[]
}

const props = withDefaults(defineProps<Props>(), {
  snKey: 'default',
  snEditor: () => [] as SnWidgetItemType[],
  modelValue: () => [] as SnWidgetItemType[]
})

const snRulesList = ref(props.snEditor)

const snPreviewModel = ref('')

const designerStore = useApprovalDesignerStore()

const designerModel = computed(() => {
  return designerStore.designerModel
})

const buildSerialNumber = computed(() => {
  let serialNumber = ''
  props.snEditor.forEach((item) => {
    serialNumber += item.data.label
  })
  // updateParentData(serialNumber)
  return serialNumber
})

const emit = defineEmits(['update:modelValue'])

// 监听子组件的更新，更新父组件的数据
const updateParentData = (val) => {
  emit('update:modelValue', val)
}
// watch(() => props.snEditor, (newValue) => {
//   buildSerialNumber(newValue)
// })

//
// onMounted(() => {
//   // const formDsgnId = designerModel.value.basic.dsgnId
//   const resId = designerModel.value.basic.resId
//
//   const snRuleList = [
//     {
//       field: props.formCreateInject.field,
//       snRules: props.snEditor
//     }
//   ]
//   const snPreview = {
//     resDsgnId: resId,
//     mode: 1,
//     snRules: snRuleList
//   }
//
//   FormDataApi.getSerialNumber(snPreview)
//     .then((res) => {
//       snPreviewModel.value = res.serialNumber
//     })
//     .finally(() => {})
//   //
// })


</script>

<style scoped></style>
